-- 定义协议类型为Mario TBox类型
    local harin_proto=Proto("MarioTbox", "Mario Harin Protocol")
-- 定义字段类型
    local harin_proto_header=ProtoField.uint16("MarioTbox.header", "header", base.HEX)
    local harin_proto_msglen=ProtoField.uint16("MarioTbox.msgLen", "msgLen", base.DEC)
    local harin_proto_encrypt=ProtoField.uint8("MarioTbox.isEncrypt", "isEncrypt", base.DEC, {[1]="encrypt", [0]="unencrypt"})

-- 关联协议与字段    
    harin_proto.fields = {
	harin_proto_header,
	harin_proto_msglen,
	harin_proto_encrypt,	
    }

-- 获取数据段的信息
-- local data_dis = Dissector.get("data")

-- wireshark在解析时有三个信息： 1. 数据缓存区 2. 包信息 3. 界面显示

function harin_proto.dissector(tvb, pinfo, tree)
-- 设置解析的协议列的名称
   debug("begin parse")
   pinfo.cols.protocol="MarioTbox"
   debug("over protocol")

   local len = tvb:len()  -- 数据包的长度
   local offset = 0 -- 头文件的偏移
   debug("data len:"..len)
   -- 获取协议树
   local protocoTree = tree:add(harin_proto, tvb(0, len), "harin tbox protocol")

   protocoTree:add(harin_proto_header, tvb(offset, 2))
   offset = offset + 2
   protocoTree:add(harin_proto_msglen, tvb(offset, 2))
   offset = offset + 2
   protocoTree:add(harin_proto_encrypt, tvb(offset, 1))
   offset = offset + 1
   protocoTree:add(stringField, tvb(offset, len))
   debug("end parse")
end

-- 将端口为7788的解析添加到系统中
local tcp_table = DissectorTable.get("tcp.port")
local tbox_port = 7788
tcp_table:add(tbox_port, harin_proto)


-- VALS_BIT_2
-- VALS_BIT_1_3 
--    local f_proto = ProtoField.uint8("multi.protocol","Protocol",base.DEC,vs_protos)
--    local f_dir = ProtoField.uint8("multi.direction","Direction",base.DEC,{ [1] = "incoming", [0] = "outgoing"})
--    local f_text = ProtoField.string("multi.text","Text")
--    local harin_proto_msglen=ProtoField.uint16("MarioTbox.msgLen", "msgLen", base.DEC)


